package de.fhaugsburg.games.boardgames.connect4.tests;

import static org.junit.Assert.assertEquals;

import org.junit.Before;
import org.junit.Test;

import de.fhaugsburg.games.boardgames.PlayerMode;
import de.fhaugsburg.games.boardgames.connect4.BinaryPiece;
import de.fhaugsburg.games.boardgames.connect4.Connect4Board;
import de.fhaugsburg.games.boardgames.connect4.Connect4Engine;
import de.fhaugsburg.games.boardgames.exceptions.GameException;

public class Connect4EngineTest {

	private Connect4Board board;
	private PlayerMode mode;
	private Connect4Engine engine;

	@Before
	public void setUp() throws Exception {
		board = new Connect4Board(8, 8);
		mode = PlayerMode.MULTI;
		engine = new Connect4Engine(board, mode);
	}

	@Test
	public void testPutPiece() throws GameException {
		engine.putPiece(3);
		assertEquals(BinaryPiece.X, board.getPiece(7, 3));
		engine.putPiece(3);
		engine.putPiece(3);
		assertEquals(BinaryPiece.X, board.getPiece(5, 3));
	}

	@Test
	public void testChangePiece() throws GameException {
		engine.putPiece(3);
		engine.putPiece(3);
		assertEquals(BinaryPiece.O, board.getPiece(6, 3));
	}

	@Test
	public void testGameOver() throws GameException {
		// 4 X pieces one up the other
		// engine.putPiece(3);
		// engine.putPiece(4);
		// engine.putPiece(3);
		// engine.putPiece(1);
		// engine.putPiece(3);
		// engine.putPiece(5);
		// engine.putPiece(3);
		// board.reset();
		// 4 X pieces diagonal from left ahead to right down.
		engine.putPiece(5);
		engine.putPiece(4);
		engine.putPiece(3);
		engine.putPiece(3);
		engine.putPiece(3);
		engine.putPiece(2);
		engine.putPiece(2);
		engine.putPiece(2);
		engine.putPiece(2);
		engine.putPiece(0);
		engine.putPiece(4); // winning piece

	}

}
